﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data.SqlClient;
using System.Data;
using System.Web.Security;
using vncom.Models;

namespace vncom.Controllers
{
    public class MemberController : Controller
    {
        //
        // GET: /Member/

        public ActionResult Index(string id)
        {
            string _layout = "";
            if (Membership.GetUser() != null)
            {
                string domain = DataProvider.getDomain(Membership.GetUser().UserName);
                if (domain == id)
                {
                    _layout = "1";
                }
            }
            ViewData["layout"] = _layout;

            List<SqlParameter> Pram = new List<SqlParameter>();
            SqlParameter Domain = new SqlParameter("@Username", SqlDbType.VarChar);
            Domain.Value = id;
            Pram.Add(Domain);
            DataTable dts = DataProvider.SelectStoreProcedure("User_GetByUserName", Pram);
            if (dts.Rows.Count > 0)
            {
                var Prams = setData(id, dts.Rows[0]["TemplateID"].ToString(), "F_SanPham_List", "1");
                var dtb = DataProvider.SelectStoreProcedure("M_Tamplate_Get", Prams);
                ViewData["M_Tamplate_Get"] = dtb.Rows[0]["displayTPM"].ToString();
            }
            return View();
        }

        [Authorize]
        public ActionResult Profile()
        {
            return View();
        }

        [Authorize]
        public ActionResult QuanLyBanner()
        {
            var username = Membership.GetUser().UserName;
            var bannerSetting = DataServices.GetBannerSetting(username);
            Banner banner = new Banner();
            banner.BannerType = int.Parse(bannerSetting[SettingKeys.BannerType]);
            banner.ImageList = DataServices.GetBannerImage(username);
            banner.ImageURL = bannerSetting.ContainsKey(SettingKeys.ImageBanner) ? bannerSetting[SettingKeys.ImageBanner] : "";
            banner.FlashURL = bannerSetting.ContainsKey(SettingKeys.FlashBanner) ? bannerSetting[SettingKeys.FlashBanner] : "";
            return View();
        }

        public List<SqlParameter> setData(string domain, string template, string type, string id)
        {
            List<SqlParameter> Prams = new List<SqlParameter>();
            SqlParameter Domain = new SqlParameter("@Domain", SqlDbType.VarChar);
            Domain.Value = domain;
            Prams.Add(Domain);
            SqlParameter M_TemplateID = new SqlParameter("@M_TemplateID", SqlDbType.Int);
            M_TemplateID.Value = template;
            Prams.Add(M_TemplateID);
            SqlParameter pType = new SqlParameter("@pType", SqlDbType.VarChar);
            pType.Value = type;
            Prams.Add(pType);
            SqlParameter pID = new SqlParameter("@pID", SqlDbType.Int);
            pID.Value = id;
            Prams.Add(pID);
            return Prams;
        }
    }
}
